package com.lj.back.manage.scaffold.module.sys.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lj.back.manage.scaffold.module.sys.DO.SysUserDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Set;

/**
 * @author lv
 */
@Mapper
@Repository
public interface SysUserDao extends BaseMapper<SysUserDO> {

    /**
     * 根据token获取用户信息
     * @param token 请求token
     * @return
     */
    SysUserDO selectUserByToken(String token);

    /**
     * 更新或新增用户角色信息
     * @param id 用户ID
     * @param roleIds
     * @return
     */
    int insertUserRole(@NotNull(message = "{user.id.notnull}") @Param("userId") Long id,
                    @NotEmpty(message = "{user.roleIds.notnull}") @Param("roleIds") Set<Long> roleIds);

    /**
     * 根据用户ID删除关联角色
     * @param id
     * @return
     */
    int deleteUserRoleByUserId(@NotNull(message = "{user.id.notnull}") @Param("userId")Long id);
}